<?php

// 连接数据库
$conn = mysqli_connect("localhost", "用户名", "密码", "数据库名");

// 检查连接是否成功
if (!$conn) {
    die("连接失败: " . mysqli_connect_error());
}

// 插入数据
$sql = "INSERT INTO 表名 (字段1, 字段2, 字段3) VALUES ('值1', '值2', '值3')";
if (mysqli_query($conn, $sql)) {
    echo "插入数据成功";
} else {
    echo "Error: " . $sql . "<br>" . mysqli_error($conn);
}

// 更新数据
$sql = "UPDATE 表名 SET 字段1='新值1' WHERE 字段2='条件值'";
if (mysqli_query($conn, $sql)) {
    echo "更新数据成功";
} else {
    echo "Error: " . $sql . "<br>" . mysqli_error($conn);
}

// 删除数据
$sql = "DELETE FROM 表名 WHERE 字段='条件值'";
if (mysqli_query($conn, $sql)) {
    echo "删除数据成功";
} else {
    echo "Error: " . $sql . "<br>" . mysqli_error($conn);
}

// 查询数据
$sql = "SELECT * FROM 表名 WHERE 字段='条件值'";
$result = mysqli_query($conn, $sql);

if (mysqli_num_rows($result) > 0) {
    // 输出每行数据
    while ($row = mysqli_fetch_assoc($result)) {
        echo "字段1: " . $row["字段1"] . " - 字段2: " . $row["字段2"] . " - 字段3: " . $row["字段3"] . "<br>";
    }
} else {
    echo "0 结果";
}

// 关闭连接
mysqli_close($conn);




